package com.wjk.test;

/**
 * @author : RobertWei
 * time: 2021/9/24    14:42
 * description:
 */

public class Answer {

    public ListNode removeNthFromEnd(ListNode head , int n){

        ListNode dummy = new ListNode(0, head);
        ListNode first = head;
        ListNode second = dummy;
        for (int i = 0; i < n; ++i) {
            first = first.next;
        }
        while (first != null) {
            first = first.next;
            second = second.next;
        }
        second.next = second.next.next;
        ListNode ans = dummy.next;
        return ans;


    }

}
